<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 数组的map方法:可以对数组中的每个元素进行操作
        let arr = [1,20,-5,3];
        arr = arr.map(item=>item*2);
        console.log(arr);
        // 数组的reduce()方法
        let res = arr.reduce((preVal,curVal)=>{
            console.log("上一次处理的值:"+preVal);
            console.log("当前正在处理的值："+curVal);
            return preVal+curVal;
        });
        console.log(res);
    </script>
</body>
</html>